home *** CD-ROM | disk | FTP | other *** search
/ PLAYymate for OS/2 / Playmate for OS2.iso / p4os2035 / biocmd.c < prev    next >
C/C++ Source or Header  |  1989-02-07  |  6KB  |  222 lines

  1. /*  BioDlg() - Dialog Box routine.
  2. *
  3. *   Created by Microsoft Corp., 1989
  4. *
  5. *   Purpose:
  6. *       Allow setting of birthdate and day of interest for basing biorhythm
  7. *       calculation and display.
  8. *
  9. *   Arguments:
  10. *       hDlg          - Handle of Dialog Box owning message
  11. *       message       - Message itself
  12. *       mp1           - Extra message-dependent info
  13. *       mp2           - Extra message-dependent info
  14. *
  15. *   Globals (modified):
  16. *       Born          - Birthdate in julian days.  Read from OS2.INI.
  17. *       SelectDay     - Current day being tracked, day is highlighted.  Is
  18. *                       in units of days from birth date.  Date of present
  19. *                       day initially used in WM_CREATE.
  20. *       Day           - Day number from date born which is top line being
  21. *                       displayed.  Initially three days before SelectDay.
  22. *       bBorn         - Boolean indicating whether valid birtdate entered or
  23. *                       defined in OS2.INI.  Nothing graphed until valid.
  24. *
  25. *   Globals (referenced):
  26. *       hAB           - Handle to the Anchor Block
  27. *       szAppName[]   - RC file program name (Biorhythm).
  28. *
  29. *   Description:
  30. *       Biorythm cycles start on the date of birth and the state of
  31. *       of these cycles may be viewed on the selected date.  A check
  32. *       box is provided to update (record) the birthdate in the WIN.INI
  33. *       file so that it will be automatically available in subsequent
  34. *       sessions.
  35. *
  36. *   Limits:
  37. *       Minor error checking is provided when OK is selected to make
  38. *       sure that the dates specified fall in the 20th and 21st
  39. *       centuries.  No error checking is attempted to verify correct
  40. *       month or day of month entries. 
  41. *
  42. */
  43.  
  44. #define INCL_WIN
  45. #include <os2.h>
  46.  
  47. #include "bio.h"
  48. #include <math.h>
  49. #include <stdio.h>
  50.  
  51. /* Read-only global variables */
  52. extern HAB      hAB;
  53. extern char     szAppName[];
  54.  
  55. /* Global variables (modified) */
  56. extern long     SelectDay, Day;
  57. extern double   Born;
  58. extern BOOL     bBorn;
  59.  
  60. /* Function prototypes */
  61. void InitBioDlg(HWND);
  62. void BioDlgCmd(HWND, MPARAM);
  63.  
  64. MRESULT CALLBACK BioDlg( hDlg, message, mp1, mp2 )
  65. HWND    hDlg;
  66. USHORT  message;
  67. MPARAM  mp1;
  68. MPARAM  mp2;
  69. {
  70.     switch( message ) {
  71.         case WM_INITDLG:
  72.         InitBioDlg(hDlg);
  73.         break;
  74.  
  75.         case WM_COMMAND:
  76.         BioDlgCmd(hDlg, mp1);
  77.         break;
  78.  
  79.         default:
  80.             return( WinDefDlgProc( hDlg, message, mp1, mp2 ) );
  81.  
  82.     }
  83.     return 0L;
  84. }
  85.  
  86.  
  87. /*  About() - General purpose About dialog box.
  88. *
  89. *   Purpose:
  90. *       Provide program propoganda.
  91. *
  92. *   Arguments:
  93. *       hDlg          - Handle of Dialog Box owning message
  94. *       message       - Message itself
  95. *       mp1           - Extra message-dependent info
  96. *       mp2           - Extra message-dependent info
  97. *
  98. *   Globals:
  99. *       none
  100. *
  101. *   Limits:
  102. *       N/A
  103. *
  104. */
  105.  
  106. MRESULT CALLBACK About( hWndDlg, message, mp1, mp2 )
  107. HWND   hWndDlg;
  108. USHORT message;
  109. MPARAM  mp1;
  110. MPARAM  mp2;
  111. {
  112.     switch( message )
  113.     {
  114.       case WM_COMMAND:
  115.         switch( LOUSHORT( mp1 ) )
  116.         {
  117.           case DID_OK:
  118.             WinDismissDlg( hWndDlg, TRUE );
  119.             break;
  120.  
  121.           default:
  122.             break;
  123.         }
  124.         break;
  125.  
  126.       default:
  127.         return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
  128.     }
  129.     return( FALSE );
  130. }
  131.  
  132.  
  133. void InitBioDlg(HWND hDlg) {
  134. /*
  135.      If valid OS2.INI info, fill in Birth date edit fields
  136. */
  137.     USHORT    year, month;
  138.     double      day;
  139.  
  140.     if (bBorn) {
  141.       calendar( Born, (int *)&year, (int *)&month, &day );
  142.       WinSetDlgItemShort( hDlg, ID_BDYEAR, year, FALSE );
  143.       WinSetDlgItemShort( hDlg, ID_BDMONTH, month, FALSE );
  144.       WinSetDlgItemShort( hDlg, ID_BDDAY, (int)day, FALSE );
  145.     }
  146.     /* Display current date or date highlighted */
  147.     calendar( Born+SelectDay, (int *)&year, (int *)&month, &day );
  148.     WinSetDlgItemShort( hDlg, ID_YEAR, year, FALSE );
  149.     WinSetDlgItemShort( hDlg, ID_MONTH, month, FALSE );
  150.     WinSetDlgItemShort( hDlg, ID_DAY, (int)day, FALSE );
  151. }
  152.  
  153.  
  154. void BioDlgCmd(HWND hDlg, MPARAM mp1) {
  155. /*
  156.     Bio Dialog Box routine WM_COMMAND processor
  157. */
  158.     USHORT    year, month, iDay;
  159.     double      day;
  160.     char        szBuf[10];
  161.  
  162.     switch( LOUSHORT( mp1 ) ) {
  163.     case DID_OK:
  164.         /* Get the birthday edit field values */
  165.         WinQueryDlgItemShort( hDlg, ID_BDYEAR, &year, FALSE );
  166.         WinQueryDlgItemShort( hDlg, ID_BDMONTH, &month, FALSE );
  167.         WinQueryDlgItemShort( hDlg, ID_BDDAY, &iDay, FALSE );
  168.         day = (double)iDay;
  169.         /* Check that date is within acceptable range */
  170.         if (year<1900 || year>2100) {
  171.            WinMessageBox( HWND_DESKTOP, hDlg,
  172.                   "Dates valid from 1900-2100",
  173.                   "Birthday!", NULL,
  174.                   MB_OK | MB_ICONEXCLAMATION );
  175.            break;
  176.         }
  177.         /* Get julian date of birth date */
  178.         Born = julian( year, month, day );
  179.  
  180.         /* Write birth date to OS2.INI if check box checked */
  181.         if (WinSendDlgItemMsg(hDlg, ID_OS2INI, BM_QUERYCHECK, 0L, 0L)) {
  182.            sprintf(szBuf, "%d", year);
  183.           WinWriteProfileString( hAB, szAppName, "Year", szBuf );
  184.            sprintf(szBuf, "%d", month);
  185.           WinWriteProfileString( hAB, szAppName, "Month", szBuf );
  186.            sprintf(szBuf, "%d", (int)day);
  187.           WinWriteProfileString( hAB, szAppName, "Day", szBuf );
  188.         }
  189.  
  190.         /* Get selected day of interest edit field values */
  191.         WinQueryDlgItemShort( hDlg, ID_YEAR, &year, FALSE );
  192.         WinQueryDlgItemShort( hDlg, ID_MONTH, &month, FALSE );
  193.         WinQueryDlgItemShort( hDlg, ID_DAY, &iDay, FALSE );
  194.         day = (double)iDay;
  195.         /* Check that date is within acceptable range */
  196.         if (year<1900 || year>2100) {
  197.            WinMessageBox( HWND_DESKTOP, hDlg,
  198.                   "Dates valid from 1900-2100",
  199.                   "Display Date!", NULL,
  200.                   MB_OK | MB_ICONEXCLAMATION );
  201.            break;
  202.         }
  203.  
  204.         /* Compute number of days since birth */
  205.          SelectDay  = (long)(julian( year, month, day ) - Born);
  206.         /* Top date of display is 3 days before selected day */
  207.         Day = SelectDay - 3;
  208.         /* Got a valid birthdate, enable all routines */
  209.         bBorn = TRUE;
  210.         WinDismissDlg( hDlg, TRUE );
  211.         break;
  212.  
  213.     case DID_CANCEL:
  214.         /* Nope! Exit and ignore entries */
  215.         WinDismissDlg( hDlg, FALSE );
  216.         break;
  217.  
  218.     default:
  219.         break;
  220.     }
  221. }
  222.